#include "BaseDlg.h"
#include <qevent.h>

BaseDlg::BaseDlg(QWidget *parent, const QString& title):
	QDialog(parent),
	current_btn{ Qt::NoButton }
{
	base_ui.setupUi(this);
	base_ui.lab_title->setText(title);
	this->setWindowFlags(Qt::FramelessWindowHint);
	setAttribute(Qt::WA_TranslucentBackground);
	connect(base_ui.btn_close, &QPushButton::clicked, this, &BaseDlg::reject);
	connect(base_ui.buttonNo, &QPushButton::clicked, this, &BaseDlg::reject);
	connect(base_ui.buttonYes, &QPushButton::clicked, this, &BaseDlg::accept);
	base_ui.btn_min->setVisible(false);
	base_ui.btn_restore->setVisible(false);
}

BaseDlg::~BaseDlg()
{
}

bool BaseDlg::showDialog()
{
	this->exec();
	return this->result() == DialogCode::Accepted;
}

void BaseDlg::mousePressEvent(QMouseEvent* event)
{
	this->current_btn = event->button();
	this->current_mouse_point = event->globalPos() - this->pos();
}

void BaseDlg::mouseReleaseEvent(QMouseEvent* event)
{
	if(event->button() == this->current_btn)
	{
		this->current_btn = Qt::NoButton;
	}
}

void BaseDlg::mouseMoveEvent(QMouseEvent* event)
{
	if(current_btn == Qt::LeftButton)
	{
		this->move(event->globalPos() - this->current_mouse_point);
	}
}
